// Copyright(c) 2011 Matthew McMullan, Jorel Lalicki and Mike Heise, Jorel Lalicki and Mike Heise. See copying.txt for details.

#ifndef __agml_tan_h__
#define __agml_tan_h__

// make sure that this file is never included directly
#ifndef __agml_agml_h__
#error "Include AGML from agml.h only. This file is not a valid entry point for the library."
#endif

#include <math.h>   /*  fabsf(3)  */
#include <iostream>

namespace agml {

/*!  fast tangent approximation  */
inline f32 tan(f32 theta) {
	theta = fmodf(theta,(f32)_pi);
    return sin(theta) / cos(theta); //naive
}

/*!	faster tangent approximation with domain restricted to [-pi, pi]	*/
inline f32 _tan(f32 theta) {
	return _sin(theta) / _cos(theta);//naive
}


/*	simdified tangent approx w/ restricted domain. naive implementation	*/
inline void _tan(_v128 &thetas) {
	_v128 thetas2 = thetas;
	_cos(thetas2);
	_sin(thetas);
	thetas = _mm_div_ps(thetas, thetas2);
}

/*! fast cotangent approximation    */
inline f32 _cotan(f32 theta) {
	theta = _mod(theta,(f32)_pi);
    return _cos(theta) / _sin(theta); //naive
}

/*	simdified cotangent approx w/ restricted domain. naive implementation	*/
inline void _cotan(_v128 &thetas) {
	_v128 thetas2 = thetas;
	_cos(thetas2);
	_sin(thetas);
	thetas = _mm_div_ps(thetas2, thetas);
}

/*!	arctan not yet implemented	*/
/*inline f32 atan(f32 f) {
	//...
	static const f32 points[64] = {  };
	u32 range = (u32)fabsf(f);
	u32 factor = range>=64;
	range = factor*63+(1-factor)*range;
	return points[range];
}*/

}
#endif
